//
//  LikeView.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/9/29.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

@objc protocol LikeViewDelegate {
    @objc optional func selectOperate(tag:Int) //选择操作
}

class LikeView: UIView {
    
    var likeDelegate : LikeViewDelegate?

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        let whiteView = UIView()
        whiteView.layer.cornerRadius = RATIO_H(maxNum: 10)
        whiteView.layer.masksToBounds = true
        whiteView.backgroundColor = UIColor.white
        self.addSubview(whiteView)
        
        let titleLabel = UILabel()
        titleLabel.text = standByUs
        titleLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        whiteView.addSubview(titleLabel)
        
        let likeButton = UIButton()
        likeButton.tag = 1
        likeButton.backgroundColor = UIColor.pinkColor()
        likeButton.setTitle(likeForUs, for: .normal)
        likeButton.titleLabel?.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        likeButton.addTarget(self, action: #selector(selectOperate(sender:)), for: .touchUpInside)
        whiteView.addSubview(likeButton)
        
        let unLikeButton = UIButton()
        unLikeButton.tag = 2
        unLikeButton.setTitle(notInterested, for: .normal)
        unLikeButton.setTitleColor(UIColor.pinkColor(), for: .normal)
        unLikeButton.titleLabel?.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        unLikeButton.layer.borderColor = UIColor.pinkColor().cgColor
        unLikeButton.layer.borderWidth = 1
        unLikeButton.addTarget(self, action: #selector(selectOperate(sender:)), for: .touchUpInside)
        whiteView.addSubview(unLikeButton)
        
        let backButton = UIButton()
        backButton.tag = 3
        backButton.setTitle(comeBackLater, for: .normal)
        backButton.setTitleColor(UIColor.lightGray, for: .normal)
        backButton.titleLabel?.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        backButton.layer.borderColor = UIColor.lightGray.cgColor
        backButton.layer.borderWidth = 1
        backButton.addTarget(self, action: #selector(selectOperate(sender:)), for: .touchUpInside)
        whiteView.addSubview(backButton)
        
        whiteView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 30))
            make.right.equalToSuperview().offset(RATIO(maxNum: -30))
            make.centerY.equalToSuperview()
            make.height.equalTo(RATIO(maxNum: 270))
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 30))
            make.centerX.equalToSuperview()
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(RATIO_H(maxNum: 20))
        }
        
        likeButton.snp.makeConstraints { (make) in
            make.top.equalTo(titleLabel.snp.bottom).offset(RATIO_H(maxNum: 30))
            make.left.equalToSuperview().offset(RATIO(maxNum: 20))
            make.right.equalToSuperview().offset(RATIO(maxNum: -20))
            make.height.equalTo(RATIO_H(maxNum: 40))
        }
        
        unLikeButton.snp.makeConstraints { (make) in
            make.top.equalTo(likeButton.snp.bottom).offset(RATIO_H(maxNum: 20))
            make.left.equalTo(likeButton)
            make.right.equalTo(likeButton)
            make.height.equalTo(likeButton)
        }
        
        backButton.snp.makeConstraints { (make) in
            make.top.equalTo(unLikeButton.snp.bottom).offset(RATIO_H(maxNum: 20))
            make.left.equalTo(unLikeButton)
            make.right.equalTo(unLikeButton)
            make.height.equalTo(unLikeButton)
        }
        
        
    }
    
    //MARK: 选择操作
    @objc fileprivate func selectOperate(sender:UIButton) {
        
        self.likeDelegate?.selectOperate!(tag: sender.tag)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
